#include "Home.h"
#include "Ball.h"

Home::Home(Vector2D & centre,int oriantation,GameRectangle & arene,int & score):GameObject(arene),_centre(centre),_rayon(90),_oriantation(oriantation),_score(score)
{
	CalculerEnglobant();
}
void Home::Paint(wxDC &dc)
{
	dc.SetBrush(wxBrush(wxColour("White")));
	if(!_oriantation)
		dc.DrawArc(_centre.X -_rayon ,_centre.Y,_centre.X + _rayon,_centre.Y,_centre.X,_centre.Y+1);
	else
		dc.DrawArc(_centre.X + _rayon,_centre.Y,_centre.X - _rayon,_centre.Y,_centre.X,_centre.Y-2);
	dc.SetBrush(wxBrush(wxColour("Black")));
	dc.DrawRectangle(_englobant->BL.X,_englobant->BL.Y,_englobant->TR.X-_englobant->BL.X,_englobant->TR.Y-_englobant->BL.Y);
}
int Home::Collision(DrawableObject *ob)
{
	Ball * ball = dynamic_cast<Ball *>(ob);
	if(ball==NULL)
		return 0;
	if(GameObject::Collision(ob))
	{
		double x = ball->GetCentre().X - _centre.X,
		   y = ball->GetCentre().Y - _centre.Y;
		if((x * x + y * y) < _rayon*_rayon)
		{
			_score++;
			return 10;
		}
	}
	return 0;
}
void Home::CalculerEnglobant()
{
	if(!_oriantation)
		_englobant = new GameRectangle(Vector2D(_centre.X +_rayon,_centre.Y),Vector2D(_centre.X -_rayon,_centre.Y+2));
	else
		_englobant = new GameRectangle(Vector2D(_centre.X +_rayon,_centre.Y-2),Vector2D(_centre.X -_rayon,_centre.Y));
	_invalidEnglobant = false;
}
Home::~Home(void)
{
}
